//
//  LLShoppingCartHeader.m
//  LoveLove
//
//  Created by 肖兰月 on 2019/4/9.
//  Copyright © 2019 wkf. All rights reserved.
//

#import "LLShoppingCartHeader.h"
#import "LLShoppingCartModel.h"

@interface LLShoppingCartHeader ()
@property (strong, nonatomic) LLButton *selecteBtn;
@property (strong, nonatomic) LLButton *titleBtn;
@end

@implementation LLShoppingCartHeader

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self initSubViews];
    }
    return self;
}

- (void)initSubViews {
    UIView *bgView = UIView.new;
    bgView.frame = CGRectMake(10, 10, LLScreenWidth-20, self.height-5);
    bgView.backgroundColor = UIColor.whiteColor;
    [bgView.layer addMaskWithRoundedRect:bgView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(13, 13)];
    [self addSubview:bgView];
    
    _selecteBtn = [LLInitBaseViewTool buttonWithTitle:nil image:@"unselected" titleColor:nil font:0];
    _selecteBtn.frame = CGRectMake(0, 0, self.height-10, self.height-10);
    [_selecteBtn setImage:[UIImage imageNamed:@"selected"] forState:UIControlStateSelected];
    [_selecteBtn addTarget:self action:@selector(selecteBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:_selecteBtn];
    
    _titleBtn = [LLInitBaseViewTool buttonWithTitle:nil image:@"Arrow_grey" titleColor:LLColorRGB(0) font:12];
    _titleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    _titleBtn.frame = CGRectMake(_selecteBtn.right, 0, bgView.width, self.height-10);
    [_titleBtn addTarget:self action:@selector(titleBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:_titleBtn];
}

- (void)setModel:(LLShoppingCartSectionModel *)model {
    _model = model;
    _selecteBtn.selected = model.isSelected;
    [_titleBtn setTitle:model.title forState:0];
    CGFloat titleBtnW = [CommonTools sizeOfText:model.title fontSize:12 width:(LLScreenWidth-20-40)].width + 50;
    _titleBtn.width = titleBtnW;
    [_titleBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -_titleBtn.imageView.frame.size.width, 0, _titleBtn.imageView.frame.size.width + 5)];
    [_titleBtn setImageEdgeInsets:UIEdgeInsetsMake(0, _titleBtn.titleLabel.bounds.size.width + 5, 0, -_titleBtn.titleLabel.bounds.size.width)];
}


- (void)selecteBtnClick {
    if ([self.delegate respondsToSelector:@selector(headerDidClickSelecte:)]) {
        [self.delegate headerDidClickSelecte:self];
    }
}

- (void)titleBtnClick {
    if ([self.delegate respondsToSelector:@selector(headerDidClickTitle:)]) {
        [self.delegate headerDidClickTitle:self];
    }
}
@end
